package com.telit.firecommand.service.impl;

import com.github.xiaolyuh.annotation.Cacheable;
import com.telit.firecommand.dao.GeoXzqhCunDao;
import com.telit.firecommand.service.GeoQueryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhouyu
 * @description geo实现类
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class GeoQueryServiceImpl implements GeoQueryService {
    @Autowired
    private GeoXzqhCunDao geoXzqhCunDao;

    @Override
    @Cacheable(value = "firecommand:fire:queryNameByCode",depict = "根据code获取到行政区划的名称",key="#code")
    public String queryNameByCode(String code) {
        if(StringUtils.isBlank(code)){
            return null;
        }
        return geoXzqhCunDao.queryNameByCode(code,StringUtils.isNotBlank(code)?code.length():0);
    }

    @Override
    public String queryXianByXiang(String xiangCode) {
        return geoXzqhCunDao.queryXianByXiang(xiangCode);
    }

    @Override
    public String queryXiangByCun(String cunCode, int length) {
        return geoXzqhCunDao.queryXiangByCun(cunCode,length);
    }

    @Override
    public String queryCodeByName(String name) {
        return geoXzqhCunDao.queryCodeByName(name);
    }
}
